package com.java2104.service;

import com.java2104.entity.Dept;
import com.java2104.entity.Employee;
import com.java2104.entity.Job;
import com.java2104.mapper.EmployeeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;

    public List<Employee> getEmployees(Employee employee){
        if(employee.getName()!=null){
            employee.setName(employee.getName().trim());
        }
        if(employee.getPhone()!=null){
            employee.setPhone(employee.getPhone().trim());
        }
        if(employee.getCardId()!=null){
            employee.setCardId(employee.getCardId().trim());
        }
        return employeeMapper.findEmployees(employee);
    }

    public int delete(List<Integer> ids){
        return employeeMapper.batchUpdateDeleteStatus(ids);
    }
    public Map insert(Employee employee){
        Map map=new HashMap();
        if (employeeMapper.selectCardId(employee.getCardId())==0){
            employeeMapper.insertEmployees(employee);
            map.put("status","success");
            map.put("msg","添加成功");
        }else {
            map.put("status","fail");
            map.put("msg","添加失败");
        }
        return map;

    }

    public void update(Employee employee){
        employeeMapper.updateByPrimaryKey(employee);
    }
    public Employee get(Integer id){
        return employeeMapper.findByPrimaryKey(id);
    }
}
